/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-05 07:34:23
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-24 18:40:29
 */
import 'package:badges/badges.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cloubhouse/screens/notification/notification_screen.dart';
import 'package:flutter_cloubhouse/screens/profile/profile_screen.dart';

class TopMenu extends StatelessWidget {
  const TopMenu({
    Key key,
    this.isOpen,
    this.onTap,
  }) : super(key: key);
  final bool isOpen;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    return Positioned(
      top: 0,
      right: 8,
      left: 8,
      child: isOpen
          ? buildOpenTopBarWidget(context)
          : buildCloseTopBarWidget(context),
    );
  }

  Row buildCloseTopBarWidget(BuildContext context) {
    return Row(children: [
      IconButton(
        onPressed: () {},
        icon: Icon(Icons.search),
      ),
      Spacer(),
      IconButton(
        onPressed: () {},
        icon: Icon(Icons.mail_outline),
      ),
      IconButton(
        onPressed: () {},
        icon: Icon(Icons.calendar_today_outlined),
      ),
      SizedBox(width: 8),
      GestureDetector(
        onTap: () {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => NotificationScreen(),
          ));
        },
        child: Badge(
          child: Icon(Icons.notifications_none),
          badgeColor: Colors.red,
          padding: EdgeInsets.all(8),
        ),
      ),
      SizedBox(width: 16),
      GestureDetector(
        onTap: () {
          Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => ProfileScreen(),
          ));
        },
        child: CircleAvatar(
          radius: 14,
        ),
      ),
    ]);
  }

  Widget buildOpenTopBarWidget(BuildContext context) {
    return Row(
      children: [
        IconButton(
          icon: Icon(Icons.keyboard_arrow_down),
          onPressed: onTap,
        ),
        Text(
          "All rooms",
          style: TextStyle(
            fontSize: 14,
          ),
        ),
        Spacer(),
        IconButton(icon: Icon(Icons.description_outlined), onPressed: () {}),
        SizedBox(
          width: 8,
        ),
        GestureDetector(
          onTap: () {
            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (context) => ProfileScreen(),
              ),
            );
          },
          child: CircleAvatar(
            radius: 14,
          ),
        )
      ],
    );
  }
}
